package code.google.gui.fragments.menu;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import code.google.gui.fragments.RegistrateableFragment;
import code.google.gui.fragments.interfaces.ISetFragmentListener;

import com.example.metamusicgui.R;

public class MenuFragment extends RegistrateableFragment {

	private ISetFragmentListener menuListener;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_menu, container, false);
		
		Button searchButton = (Button) rootView.findViewById(R.id.menufragment_button_search);
		searchButton.setOnClickListener(new MenuOnClickListener());
		
		Button fileButton = (Button) rootView.findViewById(R.id.menufragment_button_files);
		fileButton.setOnClickListener(new MenuOnClickListener());
		
		Button playerButton = (Button) rootView.findViewById(R.id.menufragment_button_player);
		playerButton.setOnClickListener(new MenuOnClickListener());
		
		Button settingsButton = (Button) rootView.findViewById(R.id.menufragment_button_settings);
		settingsButton.setOnClickListener(new MenuOnClickListener());
		
		return rootView;
	}
	
	
	private class MenuOnClickListener implements View.OnClickListener{

		@Override
		public void onClick(View v) {
			
			switch (v.getId()) {
			case R.id.menufragment_button_files:
				menuListener.setCurrentFragment(ISetFragmentListener.ALBUM_FRAGMENT);
				break;
			case R.id.menufragment_button_player:
				menuListener.setCurrentFragment(ISetFragmentListener.PLAYER_FRAGMENT);
				break;
			case R.id.menufragment_button_search:
				menuListener.setCurrentFragment(ISetFragmentListener.LOCAL_SEARCH_FRAGMENT);
				break;
			case R.id.menufragment_button_settings:
				menuListener.setCurrentFragment(ISetFragmentListener.SETTING1_FRAGMENT);
				break;
			}
	    }
		
	}


	@Override
	public void registrateFragmentAt(Activity context) {
		if(menuListener == null && context instanceof ISetFragmentListener){
			this.menuListener = (ISetFragmentListener)context;
		}
	}

	@Override
	public void deregistrateFragmentFrom(Activity context) {
		this.menuListener = null;	
	}

}
